// @algorithm @lc id=223 lang=cpp 
// @title rectangle-area


// @test(-3,0,3,4,0,-1,9,2)=45
// @test(-2,-2,2,2,-2,-2,2,2)=16
class Solution {
public:
    int computeArea(int ax1, int ay1, int ax2, int ay2, int bx1, int by1, int bx2, int by2) {
        int sa = (ax2 -ax1) * (ay2 - ay1);
        int sb = (bx2 -bx1) * (by2 - by1);
        int dx = min(ax2, bx2) - max(ax1, bx1);
        int dy = min(ay2, by2) - max(ay1, by1);
        int ds = max(0, dx) * max(0, dy);
        return sa + sb - ds;
    }
};